package com.tencent.ied.bk.handler;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chen_yu
 * @date 2021/3/11 5:36
 */
public class HandlerChain {

    public List<Handler> handlers = new ArrayList<>();

    /**
     * 添加过处理器链
     *
     * @param f 过滤器
     * @return FilterChain
     */
    public HandlerChain addHandler(Handler f) {
        handlers.add(f);
        return this;
    }

    /**
     * 具体的处理逻辑
     *
     * @param handlerObject 处理对象
     * @return
     */
    public HandlerObject doHandle(HandlerObject handlerObject) {
        for (Handler handler : handlers) {
            handler.handle(handlerObject);
        }
        return handlerObject;
    }
}
